<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/26
 * Time: 15:28
 */

namespace app\modules\api\controllers\open;

use app\models\Store;
use app\models\UploadConfig;
use app\models\UploadForm;
use app\opening\BaseApiResponse;
use app\models\GoodsUpLogs;

set_time_limit(0);

class ToolsController extends BaseController
{

    /**
     * 上传图片
     * @param null $name
     * @return BaseApiResponse
     * author eRic
     * dateTime 2019-08-06 11:00
     */
    public function actionUpImg($name = null)
    {
        $form                = new UploadForm();
        $form->upload_config = UploadConfig::findOne(['store_id' => 0, 'is_delete' => 0]);
        $form->store         = Store::findOne($this->store->id);
        $form->group_id      = \Yii::$app->request->get('group_id');
        $form->mch_id        = \Yii::$app->request->get('mch_id');
        return new BaseApiResponse($form->saveImage($name));
    }

    /**
     * 上传视频
     * @param null $name
     * @return BaseApiResponse
     * author eRic
     * dateTime 2019-08-06 11:00
     */
    public function actionUpVideo($name = null)
    {
        $form                = new UploadForm();
        $form->upload_config = UploadConfig::findOne(['store_id' => 0, 'is_delete' => 0]);
        $form->store         = Store::findOne($this->store->id);
        return new BaseApiResponse($form->saveVideo($name));
    }

    /**
     * 上传文件
     * @param null $name
     * @return array
     * author eRic
     * dateTime 2019-08-06 11:01
     */
    public function actionFile($name = null)
    {
        $form                = new UploadForm();
        $form->upload_config = UploadConfig::findOne(['store_id' => 0, 'is_delete' => 0]);
        $form->store         = Store::findOne($this->store->id);
        $form->group_id      = \Yii::$app->request->get('group_id');
        $form->mch_id        = \Yii::$app->request->get('mch_id');
        return new BaseApiResponse($form->saveImage($name));
    }

    /**
     * 获取商品上传日志
     * @param $store_id
     * author eRic
     * dateTime 2019-10-30 15:50
     */
    public function actionGetGoodsUplog($store_id = '')
    {
        $list = GoodsUpLogs::find();
        if($store_id){
            $list->where(['store_id' => $store_id]);
        }
        $list->orderBy('id DESC');
        return new BaseApiResponse([
            'code' => 0,
            'msg'  => '获取成功',
            'data' => $list->all(),
        ]);
    }
}
